<?php
include 'fun.inc.php';
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Search</title>
</head>
<body>

<h2>Search</h2>

<form action="" method="POST">
<p>
<input type="text" name="keywords" /> <input type="submit" value="search" />

</p>

</form>




<?php

if (isset ($_POST['keywords'])) {
	$keywords = mysql_real_escape_string(htmlentities(trim($_POST['keywords'])));

	$errors = array ();

	if (empty ($keywords)) {
		$errors[] = 'Please enter case id';
	} else
		if (strlen($keywords) < 3) {
			$errors[] = 'Your case id term must be three or more characters';
		} else
			if (search_results($keywords) === false) {
				$errors[] = 'Your search for<strong> ' . $keywords . '</strong> returned no results';
			}

	if (empty ($errors)) {

		//search

		$results = search_results($keywords);
		$results_num = count($results);

		echo '<p>Your Search for <strong>', $keywords, '</strong> returned <strong>', $results_num, '</strong> results</p>';

		foreach ($results as $result) {
			echo '<p> <strong>', $result['title'], '</strong> <br> ', $result['description'], '... <br> <a href="', $result['url'], '" target="_blank">', $result['url'], '</a> </p>';

		}

	} else {
		foreach ($errors as $error) {
			echo $error, '<br>';

		}
	}
}
?>

</body>
</html>